package com.springcloud.market.stock.controller;

import com.springcloud.market.stock.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope
@RequestMapping("/stock")
public class StockController {
    //第一次作业
    @Value("${user.name}")
    private String name;
    @Value("${user.age}")
    private Integer age;
    @RequestMapping("/info")
    public String info(){
        return "姓名："+name+"，年龄："+age;
    }
    //第三次课上作业
    @RequestMapping("/reduce")
    public String reduce() {
        System.out.println("扣减库存");
        return "扣减库存";

    }
    //    第三次作业
    @RequestMapping("/work")
    public String work() {
        System.out.println("第三次作业");
        return "第三次作业";
    }

    //第四次课
    @RequestMapping("/readStock")
        public String readStock(){
            System.out.println("网关测试：stock服务");
            return "网关测试：stock服务";
    }
//第五次作业
@Autowired
private StockService stockService;
    @PostMapping("/seata/reduce")
     public String seataReduce(@RequestParam("productId")Integer productId){
        stockService.reduce(productId);
        System.out.println("扣减库存");
        return "扣减库存"+productId;
     }
    }